<template>
    <div>
        <Form ref="formInline" :model="formInline" inline>
            <FormItem prop="company">
                <Input  v-model="formInline.company" placeholder="单位">
                </Input>
            </FormItem>
            <FormItem>
                <Button type="success" @click="search()">搜索</Button>
            </FormItem>
            <FormItem>
                <Button type="primary" @click="excelBtn()" icon="ios-cloud-upload-outline">数据导入</Button>
                <Button type="error" icon="ios-trash-outline" style="margin-left: 20px" @click="deleted()">一键清空</Button>
            </FormItem>
        </Form>
        <Table border :columns="columns12" :data="data6">
        </Table>
        <Row type="flex" justify="end" class="pg">
            <Page :total="total" show-total show-elevator @on-change="pageAction" />
        </Row>
    </div>
</template>

<script>
import { getSpvTransactionsList, deleteSpvTransactions, deleteAll, deletechaiAll } from '@/api/user'
export default {
  data () {
    return {
      total: 0,
      formInline: {
        company: ''
      },
      columns12: [
        {
          title: '交易流水号',
          key: 'batch_number',
          align: 'center'
        },
        {
          title: '金额(元)',
          key: 'money',
          align: 'center'
        },
        {
          title: '交易类型',
          key: 'transaction_type',
          align: 'center'
        },
        {
          title: '交易状态',
          key: 'transaction_status',
          align: 'center'
        },
        {
          title: '卡号/客户编号',
          key: 'card_num',
          align: 'center'
        },
        {
          title: '客户名称',
          key: 'name',
          align: 'center'
        },
        {
          title: '商品种类',
          key: 'type',
          align: 'center'
        },
        {
          title: '油量(升)',
          key: 'fuel',
          align: 'center'
        },
        {
          title: '车辆牌照',
          key: 'plat_number',
          align: 'center'
        },
        {
          title: '长车牌照',
          key: 'plat_number_long',
          align: 'center'
        },
        {
          title: '受理机构',
          key: 'acceptance_organization',
          align: 'center'
        },
        {
          title: '业务日期',
          key: 'business_time',
          align: 'center'
        },
        {
          title: '交易时间',
          key: 'transaction_time',
          align: 'center'
        },
        {
          title: '石油公司',
          key: 'oil_companies',
          align: 'center'
        },
        {
          title: '被监督单位',
          key: 'company',
          align: 'center',
          width: '80'
        }

      ],
      data6: [],
      loading: true,
      headerField: [
        { title: '交易流水号', field: 'batch_number', minWidth: 300 },
        { title: '金额', field: 'money', minWidth: 300 }
      ]
    }
  },

  props: {

  },

  components: {

  },

  computed: {

  },

  methods: {
    async init (data) {
      getSpvTransactionsList(data).then(ret => {
        this.data6 = ret.data.data.results
        this.total = ret.data.data.totalRecord
        this.data6.forEach(item => {
          let a = new Date(item.business_date)
          let y = a.getFullYear()
          let m = a.getMonth() + 1
          let d = a.getDate()
          if (m < 10) {
            m = '0' + m
          }
          if (d < 10) {
            d = '0' + d
          }
          item.business_date = y + '-' + m + '-' + d
        })
      })
    },
    excelBtn () {
      this.$router.push({
        name: 'excel'
      })
    },
    search () {
      const data = {
        company: this.formInline.company
      }
      this.init(data)
    },
    pageAction (current) {
      getSpvTransactionsList({ pageNo: current, company: this.formInline.company }).then(ret => {
        this.data6 = ret.data.data.results
      })
    },
    deleted () {
      this.$Modal.confirm({
        title: '确认要全部删除吗?',
        content: '<p>内容一旦删除将无法恢复</p>',
        loading: true,
        onOk: async () => {
          deleteSpvTransactions().then(ret => {
            this.data6 = ret.data.data.results
          })
          deleteAll().then(ret => {
            this.data6 = ret.data.data.results
          })
          deletechaiAll().then(ret => {
            this.data6 = ret.data.data.results
          })
          setTimeout(() => {
            this.$Modal.remove()
            this.$Message.success('删除成功')
          }, 1000)
        }
      })
    }
  },

  watch: {

  },

  mounted () {
    this.init()
  }

}
</script>

<style scoped>
.pg{
    margin-top: 20px;
}
</style>
